



import requests
def download_image( i,file_path,url):
    file_path='./img/'+file_path+str(i)+'.jpg'
    print(file_path)
    response = requests.get(url)
    if response.status_code == 200:
        with open(file_path, 'wb') as file:
            file.write(response.content)
        print('图片下载成功！')
    else:
        print('图片下载失败！')


def main():
    import json

    # 读取JSON文件中的数据
    with open('img_send.json') as f:
        data = json.load(f)

    # 遍历JSON数据中的键值对
    for key, value in data.items():
        print(key + ': ' , value)
        for i, url in enumerate(value):
            try:
                download_image(i, key, url)
            except BaseException as e:
                print(e)
                print(url)

if __name__=='__main__':
    main()
